import { Button, Space } from "antd";
import { FC } from "react";
import { ClearUserToken } from "../../utils";
import { useNavigate } from "react-router-dom";
import { LOGIN_PATHNAME } from "../../concats";
import useGetuserInfo from "../../hooks/useGetuserInfo";
import { resetUereInfo } from "../../store/UserInfoReducer";
import { useDispatch } from "react-redux";

const UserInfo: FC = () => {
  const { username, nickname } = useGetuserInfo()
  const nav = useNavigate()
  const dispatch = useDispatch()
  return (
    <div style={{ color: "white" }}>
      {username == '' ? <Button size='small' onClick={() => {
        nav(LOGIN_PATHNAME)
      }}>登录</Button> : <Space>
        <div>{username}--{nickname}</div>
        <Button size='small' onClick={() => {
          ClearUserToken()
          dispatch(resetUereInfo())
          nav(LOGIN_PATHNAME)
          
        }}>退出</Button>
      </Space>}

    </div>
  );
};

export default UserInfo;
